package implementation.search;

public class BinaryOrderedArray<K, V> extends AbstractOrderedArray<K, V> {


    public BinaryOrderedArray() {
        amount = 0;
        array = new EntryI[50];
    }

    public BinaryOrderedArray(int size) {
        amount = 0;
        array = new EntryI[size];
    }

    public int search(K key) {
        if(amount ==0){
            return -1;
        }
        int start = 0;
        int end = amount-1;
        while (end >= start) {
            int half = (end+start) / 2;
            int compare = key.hashCode() - (array[half].getKey()).hashCode();
            if (compare < 0) {
                end = half - 1;
            } else if (compare > 0) {
                start = half + 1;
            } else {
                return half;
            }
        }
        return -1;
    }


}

